//
//  RootViewController.m
//  SouthKoreaDoorLock
//
//  Created by Umeinfo on 2018/1/15.
//  Copyright © 2018年 andy90s. All rights reserved.
//

#import "RootViewController.h"
#import "SKRootCell.h"
#import "DoorLockControlViewController.h"

@interface RootViewController () <UITableViewDelegate, UITableViewDataSource>

// button in the list.
@property (nonatomic, strong) UITableView *listTableView;
@property (nonatomic, strong) UIImageView *headView;


@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
}

- (void)setupViews {
    [self.view addSubview:self.headView];
    [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navigationBar.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.offset(self.view.bounds.size.height/3);
    }];
    
    [self.view addSubview:self.listTableView];
    
    [self.listTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headView.mas_bottom).offset(50);
        make.width.offset(280);
        make.height.offset(250);
        make.centerX.equalTo(self.view);
    }];
    
    UIImageView *bottomLogo = [UIImageView new];
    bottomLogo.image = [UIImage imageNamed:@"ktnc_logo"];
    [self.view addSubview:bottomLogo];
    [bottomLogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.offset(40);
        make.height.offset(20);
        make.bottom.equalTo(self.view.mas_bottom).offset(-30);
    }];
}


#pragma mark - tableViewDelegate & dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self buttonTitles].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SKRootCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SKRootCell" forIndexPath:indexPath];
    cell.titleLab.text = [self buttonTitles][indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        DoorLockControlViewController *vc = [DoorLockControlViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


#pragma mark - lazy

- (UITableView *)listTableView {
    if (!_listTableView) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,300) style:UITableViewStylePlain];
        _listTableView.dataSource = self;
        _listTableView.delegate = self;
        _listTableView.tableFooterView = [UIView new];
        _listTableView.backgroundColor = [UIColor clearColor];
        _listTableView.scrollEnabled = NO;
        [_listTableView registerClass:[SKRootCell class] forCellReuseIdentifier:@"SKRootCell"];
    }
    return _listTableView;
}

- (UIImageView *)headView {
    if (!_headView) {
        _headView = [UIImageView new];
        _headView.image = [UIImage imageNamed:@"back_image"];
    }
    return _headView;
}

- (NSArray *)iconNames {
    return @[@"",@"",@""];
}

- (NSArray *)buttonTitles {
    return @[SKLANGUAGE(@"ROOT_DOOR_LOCK_CONTROL"),SKLANGUAGE(@"ROOT_IRIS_REGISTERED_LIST"),SKLANGUAGE(@"ROOT_ACCESS_RECORD")];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
  
}

@end


